<html>
<head><meta charset="utf-8"><title>Common Stacked Borrows violations · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Common.20Stacked.20Borrows.20violations.html">Common Stacked Borrows violations</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="166705270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Common%20Stacked%20Borrows%20violations/near/166705270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Common.20Stacked.20Borrows.20violations.html#166705270">(May 28 2019 at 11:11)</a>:</h4>
<p>I found that two kinds of Stacked Borrows errors are particularly common: creating <code>&amp;mut</code> that accidentally "kill" other pointers (might also happen with <code>&amp;</code> but seems to be less of an issue there), and casting a reference to a raw pointer that laters gets used to access things "next to" that reference (most common: using <code>&amp;slice[0] as *const _</code> instead of <code>slice.as_ptr()</code>). I collected those <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/133" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/133">here</a> and <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/134" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/134">here</a>. If you know other cases of these, please let me know!</p>
<p>In particular I feel I have seen more of these "slice" issues... was that in questions by you <span class="user-mention" data-user-id="116155">@Jake Goulding</span> ?</p>



<a name="166712541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Common%20Stacked%20Borrows%20violations/near/166712541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Common.20Stacked.20Borrows.20violations.html#166712541">(May 28 2019 at 12:51)</a>:</h4>
<p>I don't recall there being multiple. Just <a href="#narrow/stream/122651-general/topic/Miri.3A.20no.20item.20to.20reborrow.20for.20Unique" title="#narrow/stream/122651-general/topic/Miri.3A.20no.20item.20to.20reborrow.20for.20Unique">this most recent one</a></p>



<a name="166712840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Common%20Stacked%20Borrows%20violations/near/166712840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Common.20Stacked.20Borrows.20violations.html#166712840">(May 28 2019 at 12:54)</a>:</h4>
<p>that would be the "too much asserting of uniqueness" thing then, not "too weak raw ptrs"</p>



<a name="166712856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Common%20Stacked%20Borrows%20violations/near/166712856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Common.20Stacked.20Borrows.20violations.html#166712856">(May 28 2019 at 12:54)</a>:</h4>
<p>I thought I had more cases of <code>as_ptr</code> elsewhere... maybe I misremember.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>